package com.dsteiner.xelavos.client.domain;

import java.util.Date;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.persistence.AttributeOverrides;
import javax.persistence.Enumerated;

import com.dsteiner.widgets.client.ObjectUtil;
import com.dsteiner.widgets.client.domain.ModelObject;
import com.dsteiner.widgets.client.domain.Searchable;
import com.dsteiner.widgets.client.domain.SearchableId;
import com.dsteiner.widgets.client.domain.SearchableRefId;
import com.dsteiner.widgets.client.rpc.SearchRequest;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Searchable
public class SavedSearch extends ModelObject{

	public static final String FREQUENCY_DAILY = "Diario";
	public static final String FREQUENCY_WEEKLY = "Semanal";
	public static final String EMAIL_IF_NO_MATCHES_YES = "Si";
	public static final String EMAIL_IF_NO_MATCHES_NO = "No";

	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    @SearchableId
    private String id;
	
	@Persistent
	@SearchableRefId
    private String userId;
	
	@Persistent
	private String frequency;
	
	@Persistent
	private boolean emailIfNoMatches;
	
	@Persistent
	private String name;
	
    @Persistent
    private Date registeredDate;
    
    @Persistent
    private Date lastSentDate;

    @Persistent
	private String searchText;
    
    @Persistent
    private String searchClassName;
    
    @Persistent
    private String searchSort;
    
    public SavedSearch() {
	}

    public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof SavedSearch))
			return false;
		SavedSearch other = (SavedSearch) obj;
		return ObjectUtil.equals(getId(), other.getId());
	}

	@Override
	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getFrequency() {
		return frequency;
	}
	public void setFrequency(String frequency) {
		this.frequency = frequency;
	}
	public boolean isEmailIfNoMatches() {
		return emailIfNoMatches;
	}
	public boolean getEmailIfNoMatches() {
		return emailIfNoMatches;
	}
	public void setEmailIfNoMatches(boolean emailIfNoMatches) {
		this.emailIfNoMatches = emailIfNoMatches;
	}
	@Override
	public Date getRegisteredDate() {
		return registeredDate;
	}

	public void setRegisteredDate(Date registeredDate) {
		this.registeredDate = registeredDate;
	}
	
	public String getUserId() {
		return userId;
	}
	
	public void setUserId(String userId) {
		this.userId = userId;
	}

	
	public Date getLastSentDate() {
		return lastSentDate;
	}
	public void setLastSentDate(Date lastSentDate) {
		this.lastSentDate = lastSentDate;
	}

	@Override
	public void setId(String id) {
		this.id = id;
	}

	public void setSearchClassName(String searchClassName) {
		this.searchClassName = searchClassName;
	}
	public void setSearchSort(String searchSort) {
		this.searchSort = searchSort;
	}
	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}
	public String getSearchClassName() {
		return searchClassName;
	}
	public String getSearchSort() {
		return searchSort;
	}
	public String getSearchText() {
		return searchText;
	}

}